package com.fzrskj.cloud.free.user.utils;

import com.fzrskj.cloud.free.user.bean.UserAccountData;
import com.fzrskj.cloud.free.user.dao.UserAccountDataDao;
import ms.core.object.CObject;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserAccountDataUtils extends CObject{

	/**
	 * 根据email查询对象
	 * @param email
	 * @return
	 */
	public UserAccountData queryAccountDataByEmail(String email){
		UserAccountDataDao dao=new UserAccountDataDao();
		UserAccountData querUserAccountDataByEmail = dao.queryAccountDataByEmail(email);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return querUserAccountDataByEmail;
	}

	/**
	 * 根据用户名查询对象
	 * @return
	 */
	public UserAccountData queryAccountDataByName(String userName){
		UserAccountDataDao dao=new UserAccountDataDao();
		UserAccountData querUserAccountDataByEmail = dao.queryAccountDataByName(userName);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return querUserAccountDataByEmail;
	}

	/**
	 * 根据mobile查询对象
	 * @param mobile
	 * @return
	 */
	public UserAccountData queryAccountDataByMobile(String mobile){
		UserAccountDataDao dao=new UserAccountDataDao();
		UserAccountData querUserAccountDataByEmail = dao.queryAccountDataByMobile(mobile);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return querUserAccountDataByEmail;
	}

	/**
	 * 根据用户删除数据表
	 * @param userName
	 * @return
	 */
	public int deleteAccountByUserName(String userName){
		UserAccountDataDao dao=new UserAccountDataDao();
		int ret = dao.deleteAccountByUserName(userName);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	/**
	 * add user account data for new user registration
	 * @param userName
	 * @param email
	 * @param mobile
	 * @return -1 for error; 0 unknown error; 1 success
	 */
	public int addUserAccountData(String userName, String email, String mobile, int userId, Integer userType){
		Map<String, Object> values = new HashMap<String, Object>();
		values.put("userName", userName);
		values.put("email", email);
		values.put("mobile", mobile);
		values.put("userId", userId);
		values.put("userType", userType);
		UserAccountDataDao dao=new UserAccountDataDao();
		int ret = dao.addUserAccountData(values);
		this.setErrCode(dao.getErrCode());
		dao.dispose();
		return ret;
	}



	/**
	 * to update user account data
	 * @param userName
	 * @param j
	 * @return
	 */
	public int updateUserAccountData(String userName, JSONObject j){
		UserAccountDataDao dao=new UserAccountDataDao();
		int ret = dao.updateUseData(userName, j);
		this.setErrCode(dao.getErrCode());
		dao.dispose();
		return ret;
	}

	/**
	 * 按条件查询 数据表
	 * @param ret
	 * @return
	 */
	public List<UserAccountData> queryUserAccountdataList(Map<String, Object> cdt){
		UserAccountDataDao dao=new UserAccountDataDao();
		List<UserAccountData> ret = dao.queryUserAccountdataList(cdt);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//云主机会员数据
	public List<UserAccountData> queryCloudUadList(){
		UserAccountDataDao dao=new UserAccountDataDao();
		List<UserAccountData> ret = dao.queryCloudUadList();
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//域名会员数据
	public List<UserAccountData> queryDomainUadList(){
		UserAccountDataDao dao=new UserAccountDataDao();
		List<UserAccountData> ret = dao.queryDomainUadList();
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//消费会员数据
	public List<UserAccountData> queryConsumeUadList(){
		UserAccountDataDao dao=new UserAccountDataDao();
		List<UserAccountData> ret = dao.queryConsumeUadList();
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	/**
	 * 修改数据.
	 * @param data
	 * @param where
	 * @return
	 */
	public Integer modifyAccountData(Map<String, Object> data, Map<String, Object> where) {
		UserAccountDataDao dao=new UserAccountDataDao();
		Integer ret = dao.modUserAccountdata(data, where);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

}